<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>个人后台</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
        <link rel="shortcut icon" type="image/vnd.microsoft.icon" href="https://avatar.moonshot.cn/avatar/cmri3mecp7fdvr21ch3g" />
</head>
<body>
    <h1>个人后台</h1>

    {% with messages = get_flashed_messages() %}
    {% if messages %}
        <ul>
        {% for message in messages %}
            <li>{{ message }}</li>
        {% endfor %}
        </ul>
    {% endif %}
{% endwith %}

    <p>欢迎，{{ current_user.username }}! <a href="{{ url_for('logout') }}">注销</a></p>



        <h2>发帖</h2>

        <form method="POST" enctype="multipart/form-data">
            <li>
            <div class="post-content">
            <label for="title">标题:</label>
            <input type="text" name="title" required>  {#required为必填项#}
            <br>
            <label for="content">内容:</label>
            <textarea name="content" required></textarea>
             </div>
           <div class="post-actions">
            <label for="attachment">附件（可选）:</label>
            <input type="file" name="attachment">
               <br>
            <button type="submit" style="display:block;text-align:left;">发布</button>
           </div>
            </li>
        </form>




    <h2>我的帖子</h2>
    <ul>
        {% for post in current_user.posts %}
            <li>
                <div class="post-content">
                    <h3>标题：{{ post.title }}</h3>
                    <p>正文：{{ post.content }}</p>
                    <small>发帖时间: {{ post.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</small>
                </div>
                <div class="post-actions">
                    <form method="POST" action="{{ url_for('delete_post', post_id=post.id) }}">
                        <button type="submit">删除帖子</button>
                    </form>
                    <a href="{{ url_for('post_detail', post_id=post.id) }}">查看评论</a>
                </div>
            </li>
        {% endfor %}
    </ul>

    <a href="{{ url_for('index') }}">返回首页</a>
</body>
</html>
